﻿using Nop.Core.Domain.Blogs;
using Nop.Core.Domain.Directory;
using Nop.Core.Domain.Localization;
using Nop.Core.Domain.Messages;
using Nop.Services.Seo;
using Nop.Core.Domain.Seo;
using Nop.Core.Domain.Stores;
using Nop.Core.Infrastructure;
using Nop.Services.Localization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using Nop.Core.Domain.Polls;
using Nop.Core.Domain.News;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Topics;
using Nop.Core.Domain.Shipping;
using Nop.Core.Domain.Common;
using Nop.Core.Data;

namespace Nop.Services.Installation
{
    public partial class CodeFirstInstallationService : IInstallationService
    {
        #region Fields
        private ILocalizedEntityService _localizedEntityService;

        private string InstallationDataFilePath = string.Empty;
        private XmlDocument InstallationDataXml = new XmlDocument();
        private XmlElement DataDocumentElement;

        private Language arLang;
        private Language enLang;

        #endregion

        void IInstallationService.InstallData(string defaultUserEmail, string defaultUserPassword, bool installSampleData)
        {
            this.InstallData(defaultUserEmail, defaultUserPassword, installSampleData);
            InstallationDataFilePath = _webHelper.MapPath("~/App_Data/Install/InstallationData.xml");
            InstallationDataXml.Load(InstallationDataFilePath);
            DataDocumentElement =  InstallationDataXml.DocumentElement;

            this._localizedEntityService = EngineContext.Current.Resolve<ILocalizedEntityService>();

            InstallArabicLanguage();
            UpdateDefaultSite();
            InstallSites();
            //InstallMeasures();
            //InstallTaxCategories();
            InstallArabicCurrencies();
            
            //InstallShippingMethods();
            //InstallCustomersAndUsers(defaultUserEmail, defaultUserPassword);
            UpdateEmailAccount();
            //InstallMessageTemplates();
            //InstallTopics();
            //InstallSettings();
            InstallNopCmsLocaleResources();
            //InstallActivityLogTypes();
            //HashDefaultCustomerPassword(defaultUserEmail, defaultUserPassword);
            //InstallProductTemplates();
            //InstallCategoryTemplates();
            //InstallManufacturerTemplates();
            //InstallScheduleTasks();
            LocalizeCurrencies();


            InstallCountriesAndStates_2(defaultUserEmail);
            LocalizeCountriesAndStates();


            LocalizeShippingMethods();
            LocalizeMessageTemplates();
            LocalizeTopics();

            if (installSampleData)
            {
                LocalizeSpecificationAttributes();
                LocalizeProductAttributes();
                LocalizeCategories();
                LocalizeManufacturers();
                LocalizeProducts();
                
                InstallArabicBlogPosts();
                InstallArabicNews();
                InstallArabicPolls();
                
                //InstallForums();
                //InstallDiscounts();
            }
        }

        private void UpdateDefaultSite()
        {
            Store DefaultSite = _storeRepository.Table.FirstOrDefault();
            if (DefaultSite != null) 
            {
                XmlNode DefaultSiteNode = DataDocumentElement.SelectSingleNode("DefaultSite");
                DefaultSite.Name = DefaultSiteNode.SelectSingleNode("Name").InnerText;
                DefaultSite.Url = DefaultSiteNode.SelectSingleNode("Url").InnerText;
                DefaultSite.Hosts = DefaultSiteNode.SelectSingleNode("Hosts").InnerText;
                _storeRepository.Update(DefaultSite);
            }
        }

        private void InstallSites()
        {
            var stores = new List<Store>();
            int result = 1;
            foreach (XmlNode site in DataDocumentElement.SelectNodes("Sites/Site"))
            {
                var s = new Store()
                {
                    Name = site.SelectSingleNode("Name").InnerText,
                    Url = site.SelectSingleNode("Url").InnerText,
                    SslEnabled = false,
                    Hosts = site.SelectSingleNode("Hosts").InnerText,
                    DisplayOrder = int.TryParse(site.SelectSingleNode("DisplayOrder").InnerText, out result) ? int.Parse(site.SelectSingleNode("DisplayOrder").InnerText) : result,
                };
                stores.Add(s);
            }
            stores.ForEach(x => _storeRepository.Insert(x));
        }

        private void InstallArabicLanguage()
        {
            var language = new Language
            {
                Name = "Arabic",
                LanguageCulture = "ar-SA",
                UniqueSeoCode = "ar",
                FlagImageFileName = "sa.png",
                Published = true,
                Rtl = true,
                DisplayOrder = 2
            };
            _languageRepository.Insert(language);

            arLang = _languageRepository.Table.Single(l => l.Name == "Arabic");
            enLang = _languageRepository.Table.Single(l => l.Name == "English");

        }

        private void InstallArabicCurrencies()
        {
            var currencies = new List<Currency>();
            int DisplayOrder = 1;
            decimal Rate = 1;
            bool Published = true;
            foreach (XmlNode currency in DataDocumentElement.SelectNodes("Currencies/Currency"))
            {
                Currency c = new Currency();
                c.Name = currency.SelectSingleNode("Name").InnerText;
                c.CurrencyCode = currency.SelectSingleNode("CurrencyCode").InnerText;
                c.DisplayLocale = currency.SelectSingleNode("DisplayLocale").InnerText;
                c.CustomFormatting = currency.SelectSingleNode("CustomFormatting").InnerText;
                c.Published = bool.TryParse(currency.SelectSingleNode("Published").InnerText, out Published) ? bool.Parse(currency.SelectSingleNode("Published").InnerText) : Published;
                c.Rate = decimal.TryParse(currency.SelectSingleNode("Rate").InnerText, out Rate) ? decimal.Parse(currency.SelectSingleNode("Rate").InnerText) : Rate;
                c.DisplayOrder = int.TryParse(currency.SelectSingleNode("DisplayOrder").InnerText, out DisplayOrder) ? int.Parse(currency.SelectSingleNode("DisplayOrder").InnerText) : DisplayOrder;
                c.CreatedOnUtc = DateTime.UtcNow;
                c.UpdatedOnUtc = DateTime.UtcNow;
                currencies.Add(c);
            }
            currencies.ForEach(x => _currencyRepository.Insert(x));
        }

        private void UpdateEmailAccount()
        {
            int Port = 25;
            bool EnableSsl = false;
            bool UseDefaultCredentials = false;
            EmailAccount DefaultEmailAccount = _emailAccountRepository.Table.FirstOrDefault();
            if (DefaultEmailAccount != null)
            {
                XmlNode DefaultEmailAccountNode = DataDocumentElement.SelectSingleNode("DefaultEmailAccount");
                DefaultEmailAccount.Email = DefaultEmailAccountNode.SelectSingleNode("Email").InnerText;
                DefaultEmailAccount.DisplayName = DefaultEmailAccountNode.SelectSingleNode("DisplayName").InnerText;
                DefaultEmailAccount.Host = DefaultEmailAccountNode.SelectSingleNode("Host").InnerText;
                DefaultEmailAccount.Username = DefaultEmailAccountNode.SelectSingleNode("Username").InnerText;
                DefaultEmailAccount.Password = DefaultEmailAccountNode.SelectSingleNode("Password").InnerText;
                DefaultEmailAccount.Port = int.TryParse(DefaultEmailAccountNode.SelectSingleNode("Port").InnerText, out Port) ? int.Parse(DefaultEmailAccountNode.SelectSingleNode("Port").InnerText) : Port;
                DefaultEmailAccount.EnableSsl = bool.TryParse(DefaultEmailAccountNode.SelectSingleNode("EnableSsl").InnerText, out EnableSsl) ? bool.Parse(DefaultEmailAccountNode.SelectSingleNode("EnableSsl").InnerText) : EnableSsl;
                DefaultEmailAccount.UseDefaultCredentials = bool.TryParse(DefaultEmailAccountNode.SelectSingleNode("UseDefaultCredentials").InnerText, out UseDefaultCredentials) ? bool.Parse(DefaultEmailAccountNode.SelectSingleNode("UseDefaultCredentials").InnerText) : UseDefaultCredentials;
                _emailAccountRepository.Update(DefaultEmailAccount);
            }
        }

        private void InstallNopCmsLocaleResources()
        {
            var arLanguage_packPath = _webHelper.MapPath("~/App_Data/Localization/language_pack_ar.xml");

            var nopcms_language_pack_enFilePath = _webHelper.MapPath("~/App_Data/Localization/nopcms_language_pack_en.xml");
            var nopcms_language_pack_arFilePath = _webHelper.MapPath("~/App_Data/Localization/nopcms_language_pack_ar.xml");


            InsertLocalResources(arLanguage_packPath, arLang);
            InsertLocalResources(nopcms_language_pack_enFilePath, enLang);
            InsertLocalResources(nopcms_language_pack_arFilePath, arLang);
        }

        private void InsertLocalResources(string filePath, Language lang)
        {
            #region Parse resource files (with <Children> elements)

            //read and parse original file with resources (with <Children> elements)
            var originalXmlDocument = new XmlDocument();
            originalXmlDocument.Load(filePath);

            var resources = new List<LocaleStringResourceParent>();

            foreach (XmlNode resNode in originalXmlDocument.SelectNodes(@"//Language/LocaleResource"))
                resources.Add(new LocaleStringResourceParent(resNode));

            resources.Sort((x1, x2) => x1.ResourceName.CompareTo(x2.ResourceName));

            foreach (var resource in resources)
                RecursivelySortChildrenResource(resource);

            var sb = new StringBuilder();
            var writer = XmlWriter.Create(sb);
            writer.WriteStartDocument();
            writer.WriteStartElement("Language", "");

            writer.WriteStartAttribute("Name", "");
            writer.WriteString(originalXmlDocument.SelectSingleNode(@"//Language").Attributes["Name"].InnerText.Trim());
            writer.WriteEndAttribute();

            foreach (var resource in resources)
                RecursivelyWriteResource(resource, writer);

            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Flush();

            var parsedXml = sb.ToString();
            #endregion

            //now we have a parsed XML file (the same structure as exported language packs)
            //let's save resources
            var localizationService = EngineContext.Current.Resolve<ILocalizationService>();
            localizationService.ImportResourcesFromXml(lang, parsedXml);
        }

        private void LocalizeCurrencies()
        {
            Currency USD = _currencyRepository.Table.SingleOrDefault(x => x.CurrencyCode == "USD");
            if (USD != null)
            {
                _localizedEntityService.SaveLocalizedValue(USD, x => x.Name, "US Dollar", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(USD, x => x.Name, "دولار امريكي", arLang.Id);
            }

            Currency AUD = _currencyRepository.Table.SingleOrDefault(x => x.CurrencyCode == "AUD");
            if (AUD != null)
            {
                _localizedEntityService.SaveLocalizedValue(AUD, x => x.Name, "Australian Dollar", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(AUD, x => x.Name, "دولار استرالي", arLang.Id);
            }

            Currency GBP = _currencyRepository.Table.SingleOrDefault(x => x.CurrencyCode == "GBP");
            if (GBP != null)
            {
                _localizedEntityService.SaveLocalizedValue(GBP, x => x.Name, "British Pound", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(GBP, x => x.Name, "جنيه بريطاني", arLang.Id);
            }

            Currency CAD = _currencyRepository.Table.SingleOrDefault(x => x.CurrencyCode == "CAD");
            if (CAD != null)
            {
                _localizedEntityService.SaveLocalizedValue(CAD, x => x.Name, "Canadian Dollar", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(CAD, x => x.Name, "دولار كندي", arLang.Id);
            }

            Currency CNY = _currencyRepository.Table.SingleOrDefault(x => x.CurrencyCode == "CNY");
            if (CNY != null)
            {
                _localizedEntityService.SaveLocalizedValue(CNY, x => x.Name, "Chinese Yuan Renminbi", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(CNY, x => x.Name, "يوان صيني", arLang.Id);
            }

            Currency EUR = _currencyRepository.Table.SingleOrDefault(x => x.CurrencyCode == "EUR");
            if (EUR != null)
            {
                _localizedEntityService.SaveLocalizedValue(EUR, x => x.Name, "Euro", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(EUR, x => x.Name, "يورو", arLang.Id);
            }

            Currency HKD = _currencyRepository.Table.SingleOrDefault(x => x.CurrencyCode == "HKD");
            if (HKD != null)
            {
                _localizedEntityService.SaveLocalizedValue(HKD, x => x.Name, "Hong Kong Dollar", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(HKD, x => x.Name, "دولار هونج كونج", arLang.Id);
            }

            Currency JPY = _currencyRepository.Table.SingleOrDefault(x => x.CurrencyCode == "JPY");
            if (JPY != null)
            {
                _localizedEntityService.SaveLocalizedValue(JPY, x => x.Name, "Japanese Yen", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(JPY, x => x.Name, "ين يباني", arLang.Id);
            }

            Currency RUB = _currencyRepository.Table.SingleOrDefault(x => x.CurrencyCode == "RUB");
            if (RUB != null)
            {
                _localizedEntityService.SaveLocalizedValue(RUB, x => x.Name, "Russian Rouble", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(RUB, x => x.Name, "روبل روسي", arLang.Id);
            }

            Currency SEK = _currencyRepository.Table.SingleOrDefault(x => x.CurrencyCode == "SEK");
            if (SEK != null)
            {
                _localizedEntityService.SaveLocalizedValue(SEK, x => x.Name, "Swedish Krona", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(SEK, x => x.Name, "كرونة سويدية", arLang.Id);
            }

            Currency RON = _currencyRepository.Table.SingleOrDefault(x => x.CurrencyCode == "RON");
            if (RON != null)
            {
                _localizedEntityService.SaveLocalizedValue(RON, x => x.Name, "Romanian Leu", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(RON, x => x.Name, "ليو روماني", arLang.Id);
            }

            Currency EGP = _currencyRepository.Table.SingleOrDefault(x => x.CurrencyCode == "EGP");
            if (EGP != null)
            {
                _localizedEntityService.SaveLocalizedValue(EGP, x => x.Name, "Egyptian pound", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(EGP, x => x.Name, "جنيه مصري", arLang.Id);
            }

           Currency AED = _currencyRepository.Table.SingleOrDefault(x => x.CurrencyCode == "AED");
            if (AED != null)
            {
                _localizedEntityService.SaveLocalizedValue(AED, x => x.Name, "UAE Dirham", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(AED, x => x.Name, "درهم أمراتي", arLang.Id);
            }

        }

        private void LocalizeShippingMethods()
        {

            ShippingMethod InStorePickup = _shippingMethodRepository.Table.SingleOrDefault(x => x.Name == "In-Store Pickup");
            if (InStorePickup != null)
            {
                _localizedEntityService.SaveLocalizedValue(InStorePickup, x => x.Name, "In-Store Pickup", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(InStorePickup, x => x.Name, "الاستلام من الفرع", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(InStorePickup, x => x.Description, "Pick up your items at the store", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(InStorePickup, x => x.Description, "استلام المنتجات من احدي فروعنا", arLang.Id);
            }

            ShippingMethod ByGround = _shippingMethodRepository.Table.SingleOrDefault(x => x.Name == "By Ground");
            if (ByGround != null)
            {
                _localizedEntityService.SaveLocalizedValue(ByGround, x => x.Name, "By Ground", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ByGround, x => x.Name, "شحن بري", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(ByGround, x => x.Description, "Compared to other shipping methods, like by flight or over seas, ground shipping is carried out closer to the earth", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ByGround, x => x.Description, "مقارنة بوسائل الشحن الاخري, مثل الجوي والبحري, يكون الشحن البري افضل اذا كانت المسافة قريبة بينك وبين احد الفروع.", arLang.Id);
            }

            ShippingMethod ByAir = _shippingMethodRepository.Table.SingleOrDefault(x => x.Name == "By Air");
            if (ByAir != null)
            {
                _localizedEntityService.SaveLocalizedValue(ByAir, x => x.Name, "By Air", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ByAir, x => x.Name, "شحن جوي", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(ByAir, x => x.Description, "The one day air shipping", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ByAir, x => x.Description, "الشحن الجوي خلال يوم", arLang.Id);
            }
        }

        private void LocalizeTopics()
        {
            Topic AboutUs = _topicRepository.Table.SingleOrDefault(x => x.SystemName == "AboutUs");
            if (AboutUs != null)
            {
                _localizedEntityService.SaveLocalizedValue(AboutUs, x => x.Title, "About Us", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(AboutUs, x => x.Title, "من نحن", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(AboutUs, x => x.Body, "<p>Put your &quot;About Us&quot; information here. You can edit this in the admin site.</p>", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(AboutUs, x => x.Body, "<p>ضع ما تريده ان يظهر فى صفحة من نحن هنا. يمكنك تعديل النص من لوحة التحكم.</p>", arLang.Id);
            }

            Topic CheckoutAsGuestOrRegister = _topicRepository.Table.SingleOrDefault(x => x.SystemName == "CheckoutAsGuestOrRegister");
            if (CheckoutAsGuestOrRegister != null)
            {
                _localizedEntityService.SaveLocalizedValue(CheckoutAsGuestOrRegister, x => x.Title, "Checkout As Guest Or Register", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(CheckoutAsGuestOrRegister, x => x.Title, "الشراء بدون تسجيل او قم بالتسجيل", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(CheckoutAsGuestOrRegister, x => x.Body, "<p><strong>Register and save time!</strong><br />Register with us for future convenience:</p><ul><li>Fast and easy check out</li><li>Easy access to your order history and status</li></ul>", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(CheckoutAsGuestOrRegister, x => x.Body, "<p><strong>سجل ووفر الوقت</strong><br />سجل بالموقع لتستفيد من خدمات الموقع :</p><ul><li>شراء سريع وسهل</li><li>سهولة الوصول لقائمة بمشترياتك</li></ul>", arLang.Id);
            }

            Topic ConditionsOfUse = _topicRepository.Table.SingleOrDefault(x => x.SystemName == "ConditionsOfUse");
            if (ConditionsOfUse != null)
            {
                _localizedEntityService.SaveLocalizedValue(ConditionsOfUse, x => x.Title, "Conditions of use", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ConditionsOfUse, x => x.Title, "شروط الاستخدام", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(ConditionsOfUse, x => x.Body, "<p>Put your conditions of use information here. You can edit this in the admin site.</p>", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ConditionsOfUse, x => x.Body, "<p>ضع شروط الاستخدام الخاصة بموقعك هنا . يمكنك تعديل النص من لوحة تحكم الموقع.</p>", arLang.Id);
            }

            Topic ContactUs = _topicRepository.Table.SingleOrDefault(x => x.SystemName == "ContactUs");
            if (ContactUs != null)
            {
                _localizedEntityService.SaveLocalizedValue(ContactUs, x => x.Title, "Contact Us", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ContactUs, x => x.Title, "إتصل بنا", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(ContactUs, x => x.Body, "<p>Put your contact information here. You can edit this in the admin site.</p>", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ContactUs, x => x.Body, "<p>ضع معلومات الاتصال بك هنا . يمكنك تعديل النص من لوحة تحكم الموقع.</p>", arLang.Id);
            }

            Topic ForumWelcomeMessage = _topicRepository.Table.SingleOrDefault(x => x.SystemName == "ForumWelcomeMessage");
            if (ForumWelcomeMessage != null)
            {
                _localizedEntityService.SaveLocalizedValue(ForumWelcomeMessage, x => x.Title, "Forums", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ForumWelcomeMessage, x => x.Title, "المنتديات", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(ForumWelcomeMessage, x => x.Body, "<p>Put your welcome message here. You can edit this in the admin site.</p>", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ForumWelcomeMessage, x => x.Body, "<p>يمكنك اضافة رسالة ترحيب هنا . يمكنك تعديل النص من لوحة تحكم الموقع.</p>", arLang.Id);
            }

            Topic HomePageText = _topicRepository.Table.SingleOrDefault(x => x.SystemName == "HomePageText");
            if (HomePageText != null)
            {
                _localizedEntityService.SaveLocalizedValue(HomePageText, x => x.Title, "Welcome to our site", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(HomePageText, x => x.Title, "مرحباً بك", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(HomePageText, x => x.Body, "<p>Online shopping is the process consumers go through to purchase products or services over the Internet. You can edit this in the admin site.</p><p>If you have questions, see the <a href=\"http://www.nopcms.com/documentation.aspx\">Documentation</a>, or post in the <a href=\"http://www.nopcms.com/boards/\">Forums</a> at <a href=\"http://www.nopcms.com\">nopcms.com</a></p>", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(HomePageText, x => x.Body, "<p>نظام ادارة المحتوي يمكنك من إدارة محتويات موقعك بطريقة سهلة وبسيطة . يمكنك تعدل النص من لوحة تحكم الموقع .</p><p>لاي اسألة عن النظام يمكنك مشاهدة  <a href=\"http://www.nopcms.com/documentation.aspx\">ملفات المساعدة</a> او المشاركة في  <a href=\"http://www.nopcms.com/boards/\">منتديات الحوار</a> على موقعنا  <a href=\"http://www.nopcms.com\">nopcms.com</a></p>", arLang.Id);
            }

            Topic LoginRegistrationInfo = _topicRepository.Table.SingleOrDefault(x => x.SystemName == "LoginRegistrationInfo");
            if (LoginRegistrationInfo != null)
            {
                _localizedEntityService.SaveLocalizedValue(LoginRegistrationInfo, x => x.Title, "About login / registration", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(LoginRegistrationInfo, x => x.Title, "حول تسجيل الدخول / التسجيل", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(LoginRegistrationInfo, x => x.Body, "<p>Put your login / registration information here. You can edit this in the admin site.</p>", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(LoginRegistrationInfo, x => x.Body, "<p>ضع معلومات تسجيل الدخول والتسجيل بالموقع هنا . يمكنك تعديل النصل من لوحة تحكم الموقع.</p>", arLang.Id);
            }

            Topic PrivacyInfo = _topicRepository.Table.SingleOrDefault(x => x.SystemName == "PrivacyInfo");
            if (PrivacyInfo != null)
            {
                _localizedEntityService.SaveLocalizedValue(PrivacyInfo, x => x.Title, "Privacy policy", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(PrivacyInfo, x => x.Title, "سياسة الخصوصية", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(PrivacyInfo, x => x.Body, "<p>Put your privacy policy information here. You can edit this in the admin site.</p>", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(PrivacyInfo, x => x.Body, "<p>يمكنك كتابة معلومات حول سياسة الخصوصية هنا . يمكنك تعديل النص من لوحة تحكم الموقع.</p>", arLang.Id);
            }

            Topic PageNotFound = _topicRepository.Table.SingleOrDefault(x => x.SystemName == "PageNotFound");
            if (PageNotFound != null)
            {
                _localizedEntityService.SaveLocalizedValue(PageNotFound, x => x.Title, "Page Not Found", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(PageNotFound, x => x.Title, "الصفحة غير موجودة", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(PageNotFound, x => x.Body, "<p><strong>The page you requested was not found, and we have a fine guess why.</strong><ul><li>If you typed the URL directly, please make sure the spelling is correct.</li><li>The page no longer exists. In this case, we profusely apologize for the inconvenience and for any damage this may cause.</li></ul></p>", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(PageNotFound, x => x.Body, "<p><strong>لم يتم العثور على الصفحة المطلوبة, ولا يمكننا معرفة سبب ذلك.</strong><ul><li>اذا كنت تقوم بكتابة عنوان الصفحة مباشراً , عليك التأكد من صحة ما تقوم بكتابتة.</li><li>الصفحة لم تعد موجودة بالموقع, نعتذر عن ذلك وعن اى مشاكل قد يسببها الامر .</li></ul></p>", arLang.Id);
            }

            Topic ShippingInfo = _topicRepository.Table.SingleOrDefault(x => x.SystemName == "ShippingInfo");
            if (ShippingInfo != null)
            {
                _localizedEntityService.SaveLocalizedValue(ShippingInfo, x => x.Title, "Shipping & Returns", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ShippingInfo, x => x.Title, "الشحن و الإسترجاع", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(ShippingInfo, x => x.Body, "<p>Put your shipping &amp; returns information here. You can edit this in the admin site.</p>", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ShippingInfo, x => x.Body, "<p>يمكنك كتابعة معلومات الشحن والإسترجاع هنا . يمكنك تعديل النص من لوحة تحكم الموقع.</p>", arLang.Id);
            }
        }

        private void LocalizeSpecificationAttributes()
        {
            SpecificationAttribute sa1 = _specificationAttributeRepository.Table.SingleOrDefault(x => x.Name == "Screensize");
            if (sa1 != null) 
            {
                _localizedEntityService.SaveLocalizedValue(sa1, x => x.Name, "Screen Size", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(sa1, x => x.Name, "حجم الشاشة", arLang.Id);

                SpecificationAttributeOption sa1o1 = _specificationAttributeRepository.Table.Single(sa => sa.Name == "Screensize").SpecificationAttributeOptions.SingleOrDefault(sao => sao.Name == "10.0''");
                if (sa1o1 != null)
                {
                    _localizedEntityService.SaveLocalizedValue(sa1o1, x => x.Name, "10.0 Inches", enLang.Id);
                    _localizedEntityService.SaveLocalizedValue(sa1o1, x => x.Name, "10.0 بوصة", arLang.Id);
                }

                SpecificationAttributeOption sa1o2 = _specificationAttributeRepository.Table.Single(sa => sa.Name == "Screensize").SpecificationAttributeOptions.SingleOrDefault(sao => sao.Name == "14.1''");
                if (sa1o2 != null)
                {
                    _localizedEntityService.SaveLocalizedValue(sa1o2, x => x.Name, "14.1 Inches", enLang.Id);
                    _localizedEntityService.SaveLocalizedValue(sa1o2, x => x.Name, "14.1 بوصة", arLang.Id);
                }

                SpecificationAttributeOption sa1o3 = _specificationAttributeRepository.Table.Single(sa => sa.Name == "Screensize").SpecificationAttributeOptions.SingleOrDefault(sao => sao.Name == "15.4''");
                if (sa1o3 != null)
                {
                    _localizedEntityService.SaveLocalizedValue(sa1o3, x => x.Name, "15.4 Inches", enLang.Id);
                    _localizedEntityService.SaveLocalizedValue(sa1o3, x => x.Name, "15.4 بوصة", arLang.Id);
                }

                SpecificationAttributeOption sa1o4 = _specificationAttributeRepository.Table.Single(sa => sa.Name == "Screensize").SpecificationAttributeOptions.SingleOrDefault(sao => sao.Name == "16.0''");
                if (sa1o4 != null)
                {
                    _localizedEntityService.SaveLocalizedValue(sa1o4, x => x.Name, "16.0 Inches", enLang.Id);
                    _localizedEntityService.SaveLocalizedValue(sa1o4, x => x.Name, "16.0 بوصة", arLang.Id);
                }

            }

            SpecificationAttribute sa2 = _specificationAttributeRepository.Table.SingleOrDefault(x => x.Name == "CPU Type");
            if (sa2 != null) 
            {
                _localizedEntityService.SaveLocalizedValue(sa2, x => x.Name, "CPU Type", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(sa2, x => x.Name, "نوع المعالج", arLang.Id);

                SpecificationAttributeOption sa2o1 = _specificationAttributeRepository.Table.Single(sa => sa.Name == "CPU Type").SpecificationAttributeOptions.SingleOrDefault(sao => sao.Name == "AMD");
                if (sa2o1 != null)
                {
                    _localizedEntityService.SaveLocalizedValue(sa2o1, x => x.Name, "AMD", enLang.Id);
                    _localizedEntityService.SaveLocalizedValue(sa2o1, x => x.Name, "ايه ام دي", arLang.Id);
                }

                SpecificationAttributeOption sa2o2 = _specificationAttributeRepository.Table.Single(sa => sa.Name == "CPU Type").SpecificationAttributeOptions.SingleOrDefault(sao => sao.Name == "Intel");
                if (sa2o2 != null)
                {
                    _localizedEntityService.SaveLocalizedValue(sa2o2, x => x.Name, "Intel", enLang.Id);
                    _localizedEntityService.SaveLocalizedValue(sa2o2, x => x.Name, "انتل", arLang.Id);
                }
            }


            SpecificationAttribute sa3 = _specificationAttributeRepository.Table.SingleOrDefault(x => x.Name == "Memory");
            if (sa3 != null)
            {
                _localizedEntityService.SaveLocalizedValue(sa3, x => x.Name, "Memory", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(sa3, x => x.Name, "الذاكرة", arLang.Id);

                SpecificationAttributeOption sa3o1 = _specificationAttributeRepository.Table.Single(sa => sa.Name == "Memory").SpecificationAttributeOptions.SingleOrDefault(sao => sao.Name == "1 GB");
                if (sa3o1 != null)
                {
                    _localizedEntityService.SaveLocalizedValue(sa3o1, x => x.Name, "1 GB", enLang.Id);
                    _localizedEntityService.SaveLocalizedValue(sa3o1, x => x.Name, "1 جيجا بايت", arLang.Id);
                }

                SpecificationAttributeOption sa3o2 = _specificationAttributeRepository.Table.Single(sa => sa.Name == "Memory").SpecificationAttributeOptions.SingleOrDefault(sao => sao.Name == "3 GB");
                if (sa3o2 != null)
                {
                    _localizedEntityService.SaveLocalizedValue(sa3o2, x => x.Name, "3 GB", enLang.Id);
                    _localizedEntityService.SaveLocalizedValue(sa3o2, x => x.Name, "3 جيجا بايت", arLang.Id);
                }
            }



            SpecificationAttribute sa4 = _specificationAttributeRepository.Table.SingleOrDefault(x => x.Name == "Hardrive");
            if (sa4 != null)
            {
                _localizedEntityService.SaveLocalizedValue(sa4, x => x.Name, "Hard Drive", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(sa4, x => x.Name, "القرص الصلب", arLang.Id);

                SpecificationAttributeOption sa4o1 = _specificationAttributeRepository.Table.Single(sa => sa.Name == "Hardrive").SpecificationAttributeOptions.SingleOrDefault(sao => sao.Name == "320 GB");
                if (sa4o1 != null)
                {
                    _localizedEntityService.SaveLocalizedValue(sa4o1, x => x.Name, "320 GB", enLang.Id);
                    _localizedEntityService.SaveLocalizedValue(sa4o1, x => x.Name, "320 جيجا بايت", arLang.Id);
                }

                SpecificationAttributeOption sa4o2 = _specificationAttributeRepository.Table.Single(sa => sa.Name == "Hardrive").SpecificationAttributeOptions.SingleOrDefault(sao => sao.Name == "250 GB");
                if (sa4o2 != null)
                {
                    _localizedEntityService.SaveLocalizedValue(sa4o2, x => x.Name, "250 GB", enLang.Id);
                    _localizedEntityService.SaveLocalizedValue(sa4o2, x => x.Name, "250 جيجا بايت", arLang.Id);
                }

                SpecificationAttributeOption sa4o3 = _specificationAttributeRepository.Table.Single(sa => sa.Name == "Hardrive").SpecificationAttributeOptions.SingleOrDefault(sao => sao.Name == "160 GB");
                if (sa4o3 != null)
                {
                    _localizedEntityService.SaveLocalizedValue(sa4o3, x => x.Name, "160 GB", enLang.Id);
                    _localizedEntityService.SaveLocalizedValue(sa4o3, x => x.Name, "160 جيجا بايت", arLang.Id);
                }
            }
        }

        private void LocalizeProductAttributes()
        {
            ProductAttribute Color = _productAttributeRepository.Table.SingleOrDefault(x => x.Name == "Color");
            if (Color != null)
            {
                _localizedEntityService.SaveLocalizedValue(Color, x => x.Name, "Color", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(Color, x => x.Name, "اللون", arLang.Id);
            }

            ProductAttribute CustomText = _productAttributeRepository.Table.SingleOrDefault(x => x.Name == "Custom Text");
            if (CustomText != null)
            {
                _localizedEntityService.SaveLocalizedValue(CustomText, x => x.Name, "Custom Text", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(CustomText, x => x.Name, "اللون", arLang.Id);
            }

            ProductAttribute HDD = _productAttributeRepository.Table.SingleOrDefault(x => x.Name == "HDD");
            if (HDD != null)
            {
                _localizedEntityService.SaveLocalizedValue(HDD, x => x.Name, "HDD", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(HDD, x => x.Name, "القرص الصلب", arLang.Id);
            }

            ProductAttribute OS = _productAttributeRepository.Table.SingleOrDefault(x => x.Name == "OS");
            if (OS != null)
            {
                _localizedEntityService.SaveLocalizedValue(OS, x => x.Name, "OS", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(OS, x => x.Name, "نظام التشغيل", arLang.Id);
            }

            ProductAttribute Processor = _productAttributeRepository.Table.SingleOrDefault(x => x.Name == "Processor");
            if (Processor != null)
            {
                _localizedEntityService.SaveLocalizedValue(Processor, x => x.Name, "Processor", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(Processor, x => x.Name, "المعالج", arLang.Id);
            }

            ProductAttribute RAM = _productAttributeRepository.Table.SingleOrDefault(x => x.Name == "RAM");
            if (RAM != null)
            {
                _localizedEntityService.SaveLocalizedValue(RAM, x => x.Name, "RAM", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(RAM, x => x.Name, "الذاكرة", arLang.Id);
            }

            ProductAttribute Size = _productAttributeRepository.Table.SingleOrDefault(x => x.Name == "Size");
            if (Size != null)
            {
                _localizedEntityService.SaveLocalizedValue(Size, x => x.Name, "Size", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(Size, x => x.Name, "الحجم", arLang.Id);
            }

            ProductAttribute Software = _productAttributeRepository.Table.SingleOrDefault(x => x.Name == "Software");
            if (Software != null)
            {
                _localizedEntityService.SaveLocalizedValue(Software, x => x.Name, "Software", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(Software, x => x.Name, "البرامج", arLang.Id);
            }
        }

        private void LocalizeCategories()
        {
            Category categoryBooks = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Books");
            if (categoryBooks != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryBooks, x => x.Name, "Books", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryBooks, x => x.Description, "Books category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryBooks, x => x.MetaDescription, "Books category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryBooks, x => x.MetaKeywords, "Books, Dictionary, Textbooks", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryBooks, x => x.MetaTitle, "Books", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryBooks.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryBooks.ValidateSeName("", "Books", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryBooks, x => x.Name, "الكتب", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryBooks, x => x.Description, "تصنيف الكتب", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryBooks, x => x.MetaDescription, "الكتب", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryBooks, x => x.MetaKeywords, "الكتب", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryBooks, x => x.MetaTitle, "الكتب", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryBooks.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryBooks.ValidateSeName("", "الكتب", true)
                });
            }


            Category categoryComputers = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Computers");
            if (categoryComputers != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryComputers, x => x.Name, "Computers", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryComputers, x => x.Description, "Computers category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryComputers, x => x.MetaDescription, "Computers category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryComputers, x => x.MetaKeywords, "Computers", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryComputers, x => x.MetaTitle, "Computers", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryComputers.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryComputers.ValidateSeName("", "Computers", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryComputers, x => x.Name, "أجهزة الكمبيوتر", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryComputers, x => x.Description, "تصنيف أجهزة الكمبيوتر", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryComputers, x => x.MetaDescription, "أجهزة الكمبيوتر", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryComputers, x => x.MetaKeywords, "أجهزة الكمبيوتر", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryComputers, x => x.MetaTitle, "أجهزة الكمبيوتر", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryComputers.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryComputers.ValidateSeName("", "أجهزة الكمبيوتر", true)
                });
            }

            Category categoryDesktops = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Desktops");
            if (categoryDesktops != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryDesktops, x => x.Name, "Desktops", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryDesktops, x => x.Description, "Desktops category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryDesktops, x => x.MetaDescription, "Desktops category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryDesktops, x => x.MetaKeywords, "Desktops", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryDesktops, x => x.MetaTitle, "Desktops", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryDesktops.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryDesktops.ValidateSeName("", "Desktops", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryDesktops, x => x.Name, "أجهزة مكتبة", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryDesktops, x => x.Description, "تصنيف الأجهزة المكتبية", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryDesktops, x => x.MetaDescription, "أجهزة مكتبة", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryDesktops, x => x.MetaKeywords, "أجهزة مكتبة", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryDesktops, x => x.MetaTitle, "أجهزة مكتبة", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryDesktops.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryDesktops.ValidateSeName("", "أجهزة مكتبة", true)
                });
            }

            Category categoryNotebooks = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Notebooks");
            if (categoryNotebooks != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryNotebooks, x => x.Name, "Notebooks", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryNotebooks, x => x.Description, "Notebooks category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryNotebooks, x => x.MetaDescription, "Notebooks category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryNotebooks, x => x.MetaKeywords, "Notebooks", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryNotebooks, x => x.MetaTitle, "Notebooks", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryNotebooks.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryNotebooks.ValidateSeName("", "Notebooks", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryNotebooks, x => x.Name, "أجهزة محمولة", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryNotebooks, x => x.Description, "تصنيف الأجهزة المحمولة", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryNotebooks, x => x.MetaDescription, "أجهزة محمولة", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryNotebooks, x => x.MetaKeywords, "أجهزة محمولة", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryNotebooks, x => x.MetaTitle, "أجهزة محمولة", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryNotebooks.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryNotebooks.ValidateSeName("", "أجهزة محمولة", true)
                });
            }

            Category categoryAccessories = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Accessories");
            if (categoryAccessories != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryAccessories, x => x.Name, "Accessories", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryAccessories, x => x.Description, "Accessories category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryAccessories, x => x.MetaDescription, "Accessories category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryAccessories, x => x.MetaKeywords, "Accessories", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryAccessories, x => x.MetaTitle, "Accessories", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryAccessories.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryAccessories.ValidateSeName("", "Accessories", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryAccessories, x => x.Name, "إكسسوارات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryAccessories, x => x.Description, "تصنيف الإكسسوارات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryAccessories, x => x.MetaDescription, "إكسسوارات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryAccessories, x => x.MetaKeywords, "إكسسوارات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryAccessories, x => x.MetaTitle, "إكسسوارات", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryAccessories.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryAccessories.ValidateSeName("", "إكسسوارات", true)
                });
            }

            Category categorySoftware = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Software");
            if (categorySoftware != null)
            {
                _localizedEntityService.SaveLocalizedValue(categorySoftware, x => x.Name, "Software", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categorySoftware, x => x.Description, "Software category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categorySoftware, x => x.MetaDescription, "Software category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categorySoftware, x => x.MetaKeywords, "Software", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categorySoftware, x => x.MetaTitle, "Software", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categorySoftware.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categorySoftware.ValidateSeName("", "Software", true)
                });

                _localizedEntityService.SaveLocalizedValue(categorySoftware, x => x.Name, "البرمجيات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categorySoftware, x => x.Description, "تصنيف البرمجيات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categorySoftware, x => x.MetaDescription, "البرمجيات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categorySoftware, x => x.MetaKeywords, "البرمجيات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categorySoftware, x => x.MetaTitle, "البرمجيات", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categorySoftware.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categorySoftware.ValidateSeName("", "البرمجيات", true)
                });
            }

            Category categoryGames = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Games");
            if (categoryGames != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryGames, x => x.Name, "Games", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryGames, x => x.Description, "Games category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryGames, x => x.MetaDescription, "Games category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryGames, x => x.MetaKeywords, "Games", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryGames, x => x.MetaTitle, "Games", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryGames.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryGames.ValidateSeName("", "Games", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryGames, x => x.Name, "الألعاب", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryGames, x => x.Description, "تصنيف الألعاب", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryGames, x => x.MetaDescription, "تصنيف الألعاب", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryGames, x => x.MetaKeywords, "الألعاب", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryGames, x => x.MetaTitle, "الألعاب", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryGames.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryGames.ValidateSeName("", "الألعاب", true)
                });
            }

            Category categoryElectronics = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Electronics");
            if (categoryElectronics != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryElectronics, x => x.Name, "Electronics", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryElectronics, x => x.Description, "Electronics category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryElectronics, x => x.MetaDescription, "Electronics category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryElectronics, x => x.MetaKeywords, "Electronics", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryElectronics, x => x.MetaTitle, "Electronics", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryElectronics.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryElectronics.ValidateSeName("", "Electronics", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryElectronics, x => x.Name, "الالكترونيات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryElectronics, x => x.Description, "تصنيف الالكترونيات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryElectronics, x => x.MetaDescription, "تصنيف الالكترونيات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryElectronics, x => x.MetaKeywords, "الالكترونيات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryElectronics, x => x.MetaTitle, "الالكترونيات", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryElectronics.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryElectronics.ValidateSeName("", "الالكترونيات", true)
                });
            }

            Category categoryCameraPhoto = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Camera, photo");
            if (categoryCameraPhoto != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryCameraPhoto, x => x.Name, "Camera, photo", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryCameraPhoto, x => x.Description, "Camera, photo category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryCameraPhoto, x => x.MetaDescription, "Camera, photo category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryCameraPhoto, x => x.MetaKeywords, "Camera, photo", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryCameraPhoto, x => x.MetaTitle, "Camera, photo", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryCameraPhoto.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryCameraPhoto.ValidateSeName("", "Camera, photo", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryCameraPhoto, x => x.Name, "كاميرات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryCameraPhoto, x => x.Description, "تصنيف الكاميرات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryCameraPhoto, x => x.MetaDescription, "تصنيف كاميرات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryCameraPhoto, x => x.MetaKeywords, "كاميرات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryCameraPhoto, x => x.MetaTitle, "كاميرات", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryCameraPhoto.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryCameraPhoto.ValidateSeName("", "كاميرات", true)
                });
            }

            Category categoryCellPhones = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Cell phones");
            if (categoryCellPhones != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryCellPhones, x => x.Name, "Cell phones", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryCellPhones, x => x.Description, "Cell phones category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryCellPhones, x => x.MetaDescription, "Cell phones category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryCellPhones, x => x.MetaKeywords, "Cell phones", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryCellPhones, x => x.MetaTitle, "Cell phones", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryCellPhones.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryCellPhones.ValidateSeName("", "Cell phones", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryCellPhones, x => x.Name, "الهواتف المحمولة", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryCellPhones, x => x.Description, "الهواتف المحمولة", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryCellPhones, x => x.MetaDescription, "الهواتف المحمولة", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryCellPhones, x => x.MetaKeywords, "الهواتف المحمولة", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryCellPhones, x => x.MetaTitle, "الهواتف المحمولة", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryCellPhones.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryCellPhones.ValidateSeName("", "الهواتف المحمولة", true)
                });
            }

            Category categoryApparelShoes = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Apparel & Shoes");
            if (categoryApparelShoes != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryApparelShoes, x => x.Name, "Apparel & Shoes", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryApparelShoes, x => x.Description, "Apparel & Shoes category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryApparelShoes, x => x.MetaDescription, "Apparel & Shoes category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryApparelShoes, x => x.MetaKeywords, "Apparel, Shoes", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryApparelShoes, x => x.MetaTitle, "Apparel & Shoes", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryApparelShoes.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryApparelShoes.ValidateSeName("", "Apparel & Shoes", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryApparelShoes, x => x.Name, "ملابس و أحذية", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryApparelShoes, x => x.Description, "ملابس و أحذية", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryApparelShoes, x => x.MetaDescription, "ملابس و أحذية", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryApparelShoes, x => x.MetaKeywords, "ملابس و أحذية", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryApparelShoes, x => x.MetaTitle, "ملابس و أحذية", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryApparelShoes.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryApparelShoes.ValidateSeName("", "ملابس و أحذية", true)
                });
            }

            Category categoryShirts = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Shirts");
            if (categoryShirts != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryShirts, x => x.Name, "Shirts", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryShirts, x => x.Description, "Shirts category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryShirts, x => x.MetaDescription, "Shirts category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryShirts, x => x.MetaKeywords, "Shirts", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryShirts, x => x.MetaTitle, "Shirts", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryShirts.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryShirts.ValidateSeName("", "Shirts", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryShirts, x => x.Name, "قمصان", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryShirts, x => x.Description, "قمصان", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryShirts, x => x.MetaDescription, "قمصان", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryShirts, x => x.MetaKeywords, "قمصان", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryShirts, x => x.MetaTitle, "قمصان", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryShirts.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryShirts.ValidateSeName("", "قمصان", true)
                });
            }

            Category categoryJeans = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Jeans");
            if (categoryJeans != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryJeans, x => x.Name, "Jeans", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryJeans, x => x.Description, "Jeans category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryJeans, x => x.MetaDescription, "Jeans category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryJeans, x => x.MetaKeywords, "Jeans", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryJeans, x => x.MetaTitle, "Jeans", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryJeans.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryJeans.ValidateSeName("", "Jeans", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryJeans, x => x.Name, "جينز", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryJeans, x => x.Description, "جينز", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryJeans, x => x.MetaDescription, "جينز", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryJeans, x => x.MetaKeywords, "جينز", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryJeans, x => x.MetaTitle, "جينز", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryJeans.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryJeans.ValidateSeName("", "جينز", true)
                });
            }

            Category categoryShoes = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Shoes");
            if (categoryShoes != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryShoes, x => x.Name, "Shoes", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryShoes, x => x.Description, "Shoes category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryShoes, x => x.MetaDescription, "Shoes category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryShoes, x => x.MetaKeywords, "Shoes", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryShoes, x => x.MetaTitle, "Shoes", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryShoes.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryShoes.ValidateSeName("", "Shoes", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryShoes, x => x.Name, "أحذية", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryShoes, x => x.Description, "أحذية", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryShoes, x => x.MetaDescription, "أحذية", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryShoes, x => x.MetaKeywords, "أحذية", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryShoes, x => x.MetaTitle, "أحذية", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryShoes.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryShoes.ValidateSeName("", "أحذية", true)
                });
            }

            Category categoryAccessoriesShoes = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Apparel accessories");
            if (categoryAccessoriesShoes != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryAccessoriesShoes, x => x.Name, "Apparel accessories", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryAccessoriesShoes, x => x.Description, "Apparel accessories category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryAccessoriesShoes, x => x.MetaDescription, "Apparel accessories category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryAccessoriesShoes, x => x.MetaKeywords, "Apparel accessories", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryAccessoriesShoes, x => x.MetaTitle, "Apparel accessories", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryAccessoriesShoes.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryAccessoriesShoes.ValidateSeName("", "Apparel accessories", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryAccessoriesShoes, x => x.Name, "الملابس والاكسسوارات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryAccessoriesShoes, x => x.Description, "الملابس والاكسسوارات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryAccessoriesShoes, x => x.MetaDescription, "الملابس والاكسسوارات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryAccessoriesShoes, x => x.MetaKeywords, "الملابس والاكسسوارات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryAccessoriesShoes, x => x.MetaTitle, "الملابس والاكسسوارات", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryAccessoriesShoes.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryAccessoriesShoes.ValidateSeName("", "الملابس والاكسسوارات", true)
                });
            }

            Category categoryDigitalDownloads = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Digital downloads");
            if (categoryDigitalDownloads != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryDigitalDownloads, x => x.Name, "Digital downloads", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryDigitalDownloads, x => x.Description, "Digital downloads category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryDigitalDownloads, x => x.MetaDescription, "Digital downloads category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryDigitalDownloads, x => x.MetaKeywords, "Digital downloads", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryDigitalDownloads, x => x.MetaTitle, "Digital downloads", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryDigitalDownloads.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryDigitalDownloads.ValidateSeName("", "Digital downloads", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryDigitalDownloads, x => x.Name, "التنزيلات الرقمية", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryDigitalDownloads, x => x.Description, "التنزيلات الرقمية", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryDigitalDownloads, x => x.MetaDescription, "التنزيلات الرقمية", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryDigitalDownloads, x => x.MetaKeywords, "التنزيلات الرقمية", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryDigitalDownloads, x => x.MetaTitle, "التنزيلات الرقمية", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryDigitalDownloads.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryDigitalDownloads.ValidateSeName("", "التنزيلات الرقمية", true)
                });
            }

            Category categoryJewelry = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Jewelry");
            if (categoryJewelry != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryJewelry, x => x.Name, "Jewelry", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryJewelry, x => x.Description, "Jewelry category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryJewelry, x => x.MetaDescription, "Jewelry category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryJewelry, x => x.MetaKeywords, "Jewelry", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryJewelry, x => x.MetaTitle, "Jewelry", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryJewelry.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryJewelry.ValidateSeName("", "Jewelry", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryJewelry, x => x.Name, "مجوهرات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryJewelry, x => x.Description, "مجوهرات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryJewelry, x => x.MetaDescription, "مجوهرات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryJewelry, x => x.MetaKeywords, "مجوهرات", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryJewelry, x => x.MetaTitle, "مجوهرات", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryJewelry.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryJewelry.ValidateSeName("", "مجوهرات", true)
                });
            }

            Category categoryGiftCards = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Gift Cards");
            if (categoryGiftCards != null)
            {
                _localizedEntityService.SaveLocalizedValue(categoryGiftCards, x => x.Name, "Gift Cards", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryGiftCards, x => x.Description, "Gift Cards category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryGiftCards, x => x.MetaDescription, "Gift Cards category description", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryGiftCards, x => x.MetaKeywords, "Gift Cards", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryGiftCards, x => x.MetaTitle, "Gift Cards", enLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryGiftCards.Id,
                    EntityName = "Category",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = categoryGiftCards.ValidateSeName("", "Gift Cards", true)
                });

                _localizedEntityService.SaveLocalizedValue(categoryGiftCards, x => x.Name, "بطاقات الهدايا", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryGiftCards, x => x.Description, "بطاقات الهدايا", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryGiftCards, x => x.MetaDescription, "بطاقات الهدايا", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryGiftCards, x => x.MetaKeywords, "بطاقات الهدايا", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(categoryGiftCards, x => x.MetaTitle, "بطاقات الهدايا", arLang.Id);
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = categoryGiftCards.Id,
                    EntityName = "Category",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = categoryGiftCards.ValidateSeName("", "بطاقات الهدايا", true)
                });
            }
        }

        private void LocalizeManufacturers()
        {
            Manufacturer ASUS = _manufacturerRepository.Table.SingleOrDefault(x => x.Name == "ASUS");
            if (ASUS != null)
            {
                _localizedEntityService.SaveLocalizedValue(ASUS, x => x.Name, "ASUS", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ASUS, x => x.Name, "أسوس", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(ASUS, x => x.Description, "Mainboards, video and add-on cards, CD-ROMs and accessories.", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ASUS, x => x.Description, "اللوحات الأم، والفيديو، وإضافة على بطاقات والأقراص المدمجة والاكسسوارات.", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(ASUS, x => x.MetaTitle, "ASUS Mainboards, CD-ROMs and accessories.", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ASUS, x => x.MetaTitle, "أسوس اللوحات الأم، والأقراص المدمجة والاكسسوارات.", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(ASUS, x => x.MetaDescription, "ASUS (Mainboards, video and add-on cards, CD-ROMs and accessories.)", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ASUS, x => x.MetaDescription, " (اللوحات الأم، والفيديو، وإضافة على بطاقات والأقراص المدمجة والاكسسوارات) أسوس", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(ASUS, x => x.MetaKeywords, "ASUS,Laptop,VGA,Tablet,MB,android phone,Desktop,Eee,Easy,Notebooks,notebook,NB,laptops,Display,Mobile,Smartphone,Navigation smartphone,Mobile phone,Networks,Server & Workstation,Chassis,Motherboards,Optical Storage,Graphics Cards,Multimedia,Peripherals & Accessories,accessories,Peripheral,PC Accessories,Computer Peripheral,NB Accessories,Power Supply,Thermal Solution,Eshop,All-in-one PCs,Commercial Notebooks,Commercial Desktop,Barebone PC,Pad,touch screen,Touch Panel,", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ASUS, x => x.MetaKeywords, "Desktop,الأجهزة الأكثر شيوعا,سطح المكتب,أجهزة الكمبيوتر المحمولة,شاشات العرض,الهواتف المحمولة,اللوحات الأم,كروت الشاشة,الأجهزة الطرفية و الاكسسوارات,", arLang.Id);

                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = ASUS.Id,
                    EntityName = "Manufacturer",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = ASUS.ValidateSeName("", "ASUS", true)
                });

                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = ASUS.Id,
                    EntityName = "Manufacturer",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = ASUS.ValidateSeName("", "أسوس", true)
                });
            }



            Manufacturer HP = _manufacturerRepository.Table.SingleOrDefault(x => x.Name == "HP");

            if (HP != null)
            {
                _localizedEntityService.SaveLocalizedValue(HP, x => x.Name, "HP", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(HP, x => x.Name, "أتش بي", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(HP, x => x.Description, "printers, desktops, laptops, servers, storage, enterprise solutions", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(HP, x => x.Description, "الطابعات, المكتبية, والمحمولة, الخوادم, التخزين, المشاريع حلول", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(HP, x => x.MetaTitle, "Hewlett-Packard", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(HP, x => x.MetaTitle, "هيوليت باكارد", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(HP, x => x.MetaDescription, "Search or buy HP printers, desktops, laptops, servers, storage, enterprise solutions and more", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(HP, x => x.MetaDescription, "بحث أو شراء طابعات HP، أجهزة الكمبيوتر المكتبية والمحمولة والخوادم والتخزين وحلول المشاريع وأكثر من ذلك", arLang.Id);

                _localizedEntityService.SaveLocalizedValue(HP, x => x.MetaKeywords, "printers, desktops, laptops, servers, storage, enterprise solutions", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(HP, x => x.MetaKeywords, "الطابعات, المكتبية, والمحمولة, الخوادم, التخزين, المشاريع حلول", arLang.Id);

                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = HP.Id,
                    EntityName = "Manufacturer",
                    LanguageId = enLang.Id,
                    IsActive = true,
                    Slug = HP.ValidateSeName("", "HP", true)
                });

                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = HP.Id,
                    EntityName = "Manufacturer",
                    LanguageId = arLang.Id,
                    IsActive = true,
                    Slug = HP.ValidateSeName("", "أتش بي", true)
                });
            }


        }

        private void InstallArabicBlogPosts()
        {
            var blogPosts = new List<BlogPost>
                                {
                                    new BlogPost
                                        {
                                             AllowComments = true,
                                             Language = arLang,
                                             Title = "كيف تختار برنامج إدارة محتوى لموقعك",
                                             Body = "<p>أنظمة إدارة المحتوى Content management Systems CMS أصبحت من أهم البرامج المستخدمة من قبل أصحاب المواقع. وذلك لأنها تؤمن السرعة في العمل وانشاء الموقع فضلا على أنه يوجد الكثير من انظمة ادارة المحتوى مفتوحة المصدر. ولهذا السبب يجد العديد صعوبة في اختيار النظام المناسب لموقعهم.</p><br /><p><span style='font-size: large;'><strong>ما هو نظام ادارة المحتوى؟</strong></span></p><p>هو برنامج يستخدمه أصحاب المواقع ويكون متصل بقاعدة بيانات بحيث يستطيع المدير انشاء وتعديل وتحرير شكل المحتوى بطريقة ادارية مبسطة. ويتكون من نهايتين او واجهتين: واجة الادارة او لوحة التحكم Backend وفيها يتم التحرير والانشاء والتعديل والواجهة المعروضة Frontend وفيها يظهر الموقع بالشكل المطلوب.</p><p><strong><span style='font-size: large;'>لماذا يجب أن استخدم نظام ادارة محتوى لموقعي؟</span></strong></p><p>الجواب بسيط، وهو أن المواقع في العادة لا تقتصر على النصوص والصور والتي يمكنك انشاؤها باستخدام صفحات html بسيطة، ولكن ربما ستحتاج إلى نموذج مراسلة ومحتوى ديناميكي يمكّن الزوار من التفاعل مع الموقع.</p><p><strong><span style='font-size: large;'>أخطاء شائعة عند اختيار نظام ادارة المحتوى</span></strong></p><p><strong><span style='font-size: small;'>اختيار نظام ضخم ومشهور انه للمحترفين</span></strong></p><p>هذا الخطأ شائع بدرجة كبيرة وذلك أن المبتدئ خصوصا قد يقع فريسة لسمعة أحد البرامج لدى المحترفين ومطوري المواقع. وعند بدء العمل عليه يجد صعوبة في التعامل مع هذا البرنامج أو أنه يحتاج الى وقت وتعديل بدرجة تتعدى المعقول. لذلك تجد الذي يستخدم مثل هذه الأنظمة يستسلم بعد فترة ويقوم بتغيير البرنامج ان لم يغلق الموقع من الاساس.</p><p><strong><span style='font-size: small;'>النظام المدفوع أفضل من المفتوح المصدر</span></strong></p><p>في البداية يجب أن تعرف الفرق بين المجاني ومفتوح المصدر، اطلع على الملحق الثاني بهذا الموضوع: جملة: نظام إدارة المحتوى. النظام المدفوع قد يحقق بعض رغباتك الخاصة والمميزات أو العمليات التي تريد تنفيذها في موقعك ولكن ليس بالضرورة أن يكون أفضل من البرامج مفتوحة المصدر. بل ربما يكون مفتوح المصدر أفضل لكثرة الذين يعملون على تطويره.</p><p><strong><span style='font-size: small;'>الجري خلف السمعة دون التأكد من ملائمة النظام لموقعك</span></strong></p><p>هناك انظمة لها سمعة قياسية ومعروفة لدى الكثير سواءا كانوا مطورين او مستخدمين عاديين. هذه الأنظمة مهما زادت شهرتها لا يعني أنها الأفضل لموقعك، تأكد من مميزات البرنامج وملائمته لغرض موقعك قبل اختياره.</p><p><strong><span style='font-size: small;'>الطلب من احد الخبراء أن يختار لك نظام ادارة محتوى</span></strong></p><p>هذا قرار خاطئ بلا شك، فالخبير سيختار برنامج يسهل عليه التعامل معه ولكن ربما يكون الأمر مختلف بالنسبة لك، كما أن الخبير له نظرة مختلفة عن إنشاء المواقع وادارة محتواها. هذا لا يعني أن لا تستفيد من الخبراء، ولكن اطلب منهم النصيحة وأن يبينوا لك مميزات وعيوب كل نوع. وحاول ان تشرح للخبير الغرض من موقعك في البداية فهذا سيسهل عليه الأمر.</p><p><strong><span style='font-size: small;'>معايير اختيار نظام ادارة المحتوى</span></strong></p><p>هناك الكثير من المعايير ولكن ليس جميعها ينطبق على جميع المستخدمين أو جميع المواقع والأغراض التي صنعت من أجلها، لذلك سيتم ادراج بعض المعايير التي تهم المستخدمين بشكل عام.</p><p>سهولة وسرعة التنصيب.<br />وجود لوحة تحكم سهلة خالية من التعقيد.<br />امكانية زيادة فاعلية البرنامج لعمل وظائف أخرى، عند طريق الاضافات أو التعديل.<br />سهولة انشاء تصميم خارجي أو التعديل عليه.<br />وجود دعم كبير ومتعاون للنظام.<br />أن ترتاح للتعامل معه بغض النظر عن جميع النقاط السابقة.<br />إذا اجتمعت هذه المعايير في البرنامج الذي تبحث عنه فاعلم انك اقتربت من البرنامج المناسب لموقعك ولم يتبق إلا أن تتأكد أنه يقوم بجميع الوظائف التي تريد.</p>",
                                             Tags = "CMS, إدارة المحتوي, إدارة المواقع, التجارة الالكترونية, نظام إدارة الموقع, لغات البرمجة",
                                             CreatedOnUtc = DateTime.UtcNow,
                                        },
                                    new BlogPost
                                        {
                                             AllowComments = true,
                                             Language = arLang,
                                             Title = "خدمة العملاء",
                                             Body = "<p>إذا سئلت عن خدمة العملاء ما هي؟ فقد تتبادر إلى ذهنك أمور كثيرة، لكنك قد تختزل خدمة العملاء في بعض المظاهر المحددة، مثل أن تكون لدى العميل مشكلة وتساعده على حلها، أو لديه سؤال فتساعده على الإجابة عنه، وغيرها من الوظائف المشابهة التي تقوم بها أقسام خدمة العملاء في البقالات الكبيرة والمراكز التجارية وما إلى ذلك. ولكني أعتقد أن هذا النوع من الخدمة مقصور على فئة من العملاء، وهم العملاء الذين لديهم مشكلات تحتاج إلى تدخل لحلها. أما أكثر العملاء الذين لا تواجههم مشكلات كبيرة، أو واجهتهم مشكلات ولم يرغبوا (لسبب أو لآخر) في أن يخبروا الشركة بها، فلا تقدم لهم هذه الأقسام أي خدمة. و خدمة العملاء ذات مفهوم أشمل من مجرد حل المشكلات، كما لا ينبغي أن تنتظر إلى أن يبحث عنها العميل بنفسه، فهذا دور ناقص لأن الشركة تعتني فقط بالعملاء الذين لديهم مشكلات وتجشموا عناء طرحها على الشركة، أما غيرهم فلا. خاصة أننا نعلم أن عميلاً واحدًا من كل عشرة عملاء هو الذي يذهب ويطرح مشكلته على الشركة، ويطلب المساعدة في حلها. أما التسعة الباقون فلا يكلفون أنفسهم عناء مجرد إخبار الشركة، بل إنهم قد يذهبون ولا يعودون مرة أخرى، فتخسرهم الشركة بصمت، وقد يعطون انطباعًا سيئًا عن الشركة. فهل هذا هو الهدف الذي من أجله قمنا بتخصيص أقسام وتعيين موظفين للقيام بخدمة العملاء؟</p><p>لذلك أكرر وأقول إنه يجب ألا تكون خدمة العملاء مقتصرة على أشخاص معينين يقدمون الخدمة للعميل، بل يجب أن يشارك فيها كل موظف بدءًا من المدير العام وانتهاء بحارس الشركة. أما إذا لم تستشعر الشركة وكل شخص فيها هذه المسؤولية، فإن العملاء لن يجدوا من العناية ما يستحقونه، وقد يذهبون إلى شركات أخرى منافسة تعتني بهم بشكل أفضل. ويجب ألا يتعذر بعض الموظفين بأن ذلك ليس من عملهم ، بل إن خدمة العميل من واجب كل شخص بالشركة ، لذلك يجب أن تكون خدمة العملاء فلسفة وتوجهًا عامًا لدى الشركة ككل وليس مسؤولية أشخاص معينين وأقسام محددة، بل يجب أن تكون خدمة العملاء التزامًا دائمًا من كل العاملين بالشركة وفي كل الأوقات، فذلك هو الضمان الوحيد لمستقبل الشركة، وهو الوسيلة الوحيدة لتحقيق أهدافها.</p><p>ولا تكفي مئات الآلاف التي تصرف على الإعلانات،&nbsp; لأن دورها قد يقتصر على جذب العملاء إلى داخل المحل ويتوقف، ويلعب رجال البيع الدور الباقي من خلال تقديم خدمة عالية الجودة وإقناع العميل ليس بالشراء فقط، وإنما بتكرار الشراء مرات ومرات أخرى. فالتعامل مع العملاء بتقدير واحترام يعدّ كافيًا لجعلهم يرغبون في البقاء والتعامل معك.</p>",
                                             Tags = "العملاء, خدمة العملاء, الشركات, الإدارة, موظفين",
                                             CreatedOnUtc = DateTime.UtcNow.AddSeconds(1),
                                        },
                                };
            blogPosts.ForEach(bp => _blogPostRepository.Insert(bp));

            //search engine names
            foreach (var blogPost in blogPosts)
            {
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = blogPost.Id,
                    EntityName = "BlogPost",
                    LanguageId = blogPost.LanguageId,
                    IsActive = true,
                    Slug = blogPost.ValidateSeName("", blogPost.Title, true)
                });
            }
        }

        private void InstallArabicNews()
        {
            var news = new List<NewsItem>
                                {
                                    new NewsItem
                                        {
                                             AllowComments = true,
                                             Language = arLang,
                                             Title = "هواوي تزيح الستار عن الهاتف Honor 3 المقاوم للمياه",
                                             Short = "<p>أزاحت شركة “هواوي” الستار عن الهاتف الذكي الجديد Honor 3، وهو الهاتف الذي يعد الجيل الثالث من سلسلة هواتف Honor…</p>",
                                             Full = "<p>أزاحت شركة “هواوي” الستار عن الهاتف الذكي الجديد Honor 3، وهو الهاتف الذي يعد الجيل الثالث من سلسلة هواتف Honor التي أطلقت الشركة الصينية أولى الهواتف فيها عام 2011.</p><p>ويملك الهاتف شاشة قياس 4.7 بوصة بدرجة وضوح 720×1280 بكسل، مدعومة بالمعالج K3V2E رباعي النواة من تطوير شركة “HiSilicon” المملوكة لشركة “هواوي”، والذي يعمل بسرعة 1.5 جيجاهرتز.</p><p>ودعمت “هواوي” هاتفها الذكي الجديد بذاكرة تخزين عشوائي سعة 2 جيجابايت، وذاكرة تخزين داخلية بسعة 8 جيجابايت مع منفذ لتوسيع سعة الذاكرة عبر بطاقة ذاكرة خارجية من نوع microSD.</p><p>وتبلغ دقة الكاميرا الخلفية في الهاتف Honor 3 الذكي الجديد 13.1 ميجابيكسل وهي الكاميرا المزودة بمستشعر Exmor RS وفلاش ضوئي من نوع LED مما يجعلها مناسبة للتصوير في ظروف الإضاءة الضعيفة، أما الكاميرا الامامية فتبلغ دقتها 1 ميجابيكسل.</p><p>وسوف يعمل الهاتف ببطارية بسعة 2230 ميلي أمبير/ ساعة، وسيزود بنسخة “أندرويد 4.2.2″ والإصدار 1.6 من واجهة المستخدم Emotion التي تطورها الشركة الصينية.</p><p>وزودت “هواوي” الهاتف الذكي الجديد بمعيار IP57 مما يجعله مقاوماً للمياه والغبار، ومنافساً لعدد من الهواتف الذكية المقاومة للمياه التي تم الكشف عنها مؤخراً مثل هاتف “سامسونج جالاكسي إس 4 أكتيف” وهواتف “سوني” سواء “إكسبريا Z” أو “إكسبريا ZR” أو “إكسبريا Z الترا”.</p><p>ويدعم الهاتف Honor 3 كذلك تقنية الإرسال عبر الأشعة الحمراء مما يجعله مناسباً للعمل كوحدة تحكم لأكثر من ثلاثة آلاف نوع من الأجهزة الإلكترونية بما في ذلك أجهزة التلفاز.</p><p>وتعتزم “هواوي” طرح الهاتف Honor 3 في الأسواق الصينية أولاً مقابل 310 دولار أمريكي، كما سيطرح في بعض الأسواق العالمية تحت اسم Glory 3 إلا أن الشركة لم توضح أي معلومات حول موعد توفره في بقية الأسواق.</p>",
                                             Published  = true,
                                             CreatedOnUtc = DateTime.UtcNow,
                                        },
                                    new NewsItem
                                        {
                                             AllowComments = true,
                                             Language = arLang,
                                             Title = "سامسونج تعتزم الكشف عن نسخة رخيصة من “جالاكسي نوت 3″",
                                             Short = "<p>تحمل النسخة الأرخص سعرًا شاشة من نوع LCD وكاميرا بدقة 8 ميغابيكسل.</p>",
                                             Full = "<p>تحمل النسخة الأرخص سعرًا شاشة من نوع LCD وكاميرا بدقة 8 ميغابيكسل.</p><p>أفادت معلومات جديدة نشرها موقع&nbsp;ETNews<em>&nbsp;</em>الكوري بأن شركة سامسونج تعتزم الكشف عن نسختين من هاتفها المُنتظر “جالاكسي نوت 3″ سيكون الفارق الرئيسي بينهما في دقة الشاشة ونوع الكاميرا.</p><p>ويشير المصدر بأن النسخة الأرخص سعرًا من الجهاز والتي ستكون مخصصة للأسواق النامية ستحمل شاشة من نوع LCD عوضًا عن شاشة AMOLED، كما ستحمل كاميرا بدقة 8 ميجابيكسل بدل 13 ميجابيكسل.</p><p>وكانت&nbsp;صورة مسربة لشاشة الهاتف تم نشرها أمس&nbsp;قد بينت أنها ستأتي بقياس 5.68 إنش، في حين تتضارب الأنباء حول نوع المعالج مابين معالج سامسونج&nbsp;Exynos 5420 ثماني النواة، أو معالج Snapdragon 800 رباعي النواة من شركة كوالكوم، في حين سيتوفر الجهاز بالسعات التخزينية 16 و 32 و 64 جيجابايت.</p><p>ومن المنتظر أن تكشف سامسونج عن هاتفها الجديد في الرابع من سبتمبر/أيلول ضمن فعاليات مؤتمر IFA 2013 في برلين.</p>",
                                             Published  = true,
                                             CreatedOnUtc = DateTime.UtcNow.AddSeconds(1),
                                        },
                                };
            news.ForEach(n => _newsItemRepository.Insert(n));

            //search engine names
            foreach (var newsItem in news)
            {
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = newsItem.Id,
                    EntityName = "NewsItem",
                    LanguageId = newsItem.LanguageId,
                    IsActive = true,
                    Slug = newsItem.ValidateSeName("", newsItem.Title, true)
                });
            }
        }

        private void InstallArabicPolls()
        {
            var poll1 = new Poll
            {
                Language = arLang,
                Name = "ما رأيك في الموقع؟",
                SystemKeyword = "RightColumnPoll",
                Published = true,
                DisplayOrder = 1,
            };
            poll1.PollAnswers.Add(new PollAnswer()
            {
                Name = "ممتاز",
                DisplayOrder = 1,
            });
            poll1.PollAnswers.Add(new PollAnswer()
            {
                Name = "جيد",
                DisplayOrder = 2,
            });
            poll1.PollAnswers.Add(new PollAnswer()
            {
                Name = "ضعيف",
                DisplayOrder = 3,
            });
            poll1.PollAnswers.Add(new PollAnswer()
            {
                Name = "سيئ جداً",
                DisplayOrder = 4,
            });
            _pollRepository.Insert(poll1);
        }

        private void LocalizeMessageTemplates()
        {
            MessageTemplate BlogBlogComment = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "Blog.BlogComment");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(BlogBlogComment, x => x.Subject, "%Store.Name%. New blog comment.", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(BlogBlogComment, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />A new blog comment has been created for blog post \"%BlogComment.BlogPostTitle%\".</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(BlogBlogComment, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(BlogBlogComment, x => x.Body, "Body", arLang.Id);
            }



            MessageTemplate CustomerBackInStock = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "Customer.BackInStock");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(CustomerBackInStock, x => x.Subject, "%Store.Name%. Back in stock notification", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(CustomerBackInStock, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />Hello %Customer.FullName%, <br />Product <a target=\"_blank\" href=\"%BackInStockSubscription.ProductUrl%\">%BackInStockSubscription.ProductName%</a> is in stock.</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(CustomerBackInStock, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(CustomerBackInStock, x => x.Body, "Body", arLang.Id);
            }


            MessageTemplate CustomerEmailValidationMessage = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "Customer.EmailValidationMessage");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(CustomerEmailValidationMessage, x => x.Subject, "%Store.Name%. Email validation", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(CustomerEmailValidationMessage, x => x.Body, "<a href=\"%Store.URL%\">%Store.Name%</a>  <br />  <br />  To activate your account <a href=\"%Customer.AccountActivationURL%\">click here</a>.     <br />  <br />  %Store.Name%", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(CustomerEmailValidationMessage, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(CustomerEmailValidationMessage, x => x.Body, "Body", arLang.Id);
            }


            MessageTemplate CustomerNewPM = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "Customer.NewPM");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(CustomerNewPM, x => x.Subject, "%Store.Name%. You have received a new private message", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(CustomerNewPM, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />You have received a new private message.</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(CustomerNewPM, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(CustomerNewPM, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate CustomerPasswordRecovery = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "Customer.PasswordRecovery");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(CustomerPasswordRecovery, x => x.Subject, "%Store.Name%. Password recovery", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(CustomerPasswordRecovery, x => x.Body, "<a href=\"%Store.URL%\">%Store.Name%</a>  <br />  <br />  To change your password <a href=\"%Customer.PasswordRecoveryURL%\">click here</a>.     <br />  <br />  %Store.Name%", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(CustomerPasswordRecovery, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(CustomerPasswordRecovery, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate CustomerWelcomeMessage = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "Customer.WelcomeMessage");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(CustomerWelcomeMessage, x => x.Subject, "Welcome to %Store.Name%", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(CustomerWelcomeMessage, x => x.Body, "We welcome you to <a href=\"%Store.URL%\"> %Store.Name%</a>.<br /><br />You can now take part in the various services we have to offer you. Some of these services include:<br /><br />Permanent Cart - Any products added to your online cart remain there until you remove them, or check them out.<br />Address Book - We can now deliver your products to another address other than yours! This is perfect to send birthday gifts direct to the birthday-person themselves.<br />Order History - View your history of purchases that you have made with us.<br />Products Reviews - Share your opinions on products with our other customers.<br /><br />For help with any of our online services, please email the store-owner: <a href=\"mailto:%Store.Email%\">%Store.Email%</a>.<br /><br />Note: This email address was given to us by one of our customers. If you did not signup to be a member, please send an email to <a href=\"mailto:%Store.Email%\">%Store.Email%</a>.", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(CustomerWelcomeMessage, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(CustomerWelcomeMessage, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate ForumsNewForumPost = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "Forums.NewForumPost");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(ForumsNewForumPost, x => x.Subject, "%Store.Name%. New Post Notification.", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ForumsNewForumPost, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />A new post has been created in the topic <a href=\"%Forums.TopicURL%\">\"%Forums.TopicName%\"</a> at <a href=\"%Forums.ForumURL%\">\"%Forums.ForumName%\"</a> forum.<br /><br />Click <a href=\"%Forums.TopicURL%\">here</a> for more info.<br /><br />Post author: %Forums.PostAuthor%<br />Post body: %Forums.PostBody%</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(ForumsNewForumPost, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(ForumsNewForumPost, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate ForumsNewForumTopic = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "Forums.NewForumTopic");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(ForumsNewForumTopic, x => x.Subject, "%Store.Name%. New Topic Notification.", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ForumsNewForumTopic, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />A new topic <a href=\"%Forums.TopicURL%\">\"%Forums.TopicName%\"</a> has been created at <a href=\"%Forums.ForumURL%\">\"%Forums.ForumName%\"</a> forum.<br /><br />Click <a href=\"%Forums.TopicURL%\">here</a> for more info.</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(ForumsNewForumTopic, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(ForumsNewForumTopic, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate GiftCardNotification = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "GiftCard.Notification");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(GiftCardNotification, x => x.Subject, "%GiftCard.SenderName% has sent you a gift card for %Store.Name%", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(GiftCardNotification, x => x.Body, "<p>You have received a gift card for %Store.Name%</p><p>Dear %GiftCard.RecipientName%, <br /><br />%GiftCard.SenderName% (%GiftCard.SenderEmail%) has sent you a %GiftCard.Amount% gift cart for <a href=\"%Store.URL%\"> %Store.Name%</a></p><p>You gift card code is %GiftCard.CouponCode%</p><p>%GiftCard.Message%</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(GiftCardNotification, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(GiftCardNotification, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate NewCustomerNotification = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "NewCustomer.Notification");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(NewCustomerNotification, x => x.Subject, "%Store.Name%. New customer registration", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(NewCustomerNotification, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />A new customer registered with your store. Below are the customer's details:<br />Full name: %Customer.FullName%<br />Email: %Customer.Email%</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(NewCustomerNotification, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(NewCustomerNotification, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate NewReturnRequestStoreOwnerNotification = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "NewReturnRequest.StoreOwnerNotification");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(NewReturnRequestStoreOwnerNotification, x => x.Subject, "%Store.Name%. New return request.", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(NewReturnRequestStoreOwnerNotification, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />%Customer.FullName% has just submitted a new return request. Details are below:<br />Request ID: %ReturnRequest.ID%<br />Product: %ReturnRequest.Product.Quantity% x Product: %ReturnRequest.Product.Name%<br />Reason for return: %ReturnRequest.Reason%<br />Requested action: %ReturnRequest.RequestedAction%<br />Customer comments:<br />%ReturnRequest.CustomerComment%</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(NewReturnRequestStoreOwnerNotification, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(NewReturnRequestStoreOwnerNotification, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate NewsNewsComment = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "News.NewsComment");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(NewsNewsComment, x => x.Subject, "%Store.Name%. New news comment.", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(NewsNewsComment, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />A new news comment has been created for news \"%NewsComment.NewsTitle%\".</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(NewsNewsComment, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(NewsNewsComment, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate NewsLetterSubscriptionActivationMessage = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "NewsLetterSubscription.ActivationMessage");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(NewsLetterSubscriptionActivationMessage, x => x.Subject, "%Store.Name%. Subscription activation message.", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(NewsLetterSubscriptionActivationMessage, x => x.Body, "<p><a href=\"%NewsLetterSubscription.ActivationUrl%\">Click here to confirm your subscription to our list.</a></p><p>If you received this email by mistake, simply delete it.</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(NewsLetterSubscriptionActivationMessage, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(NewsLetterSubscriptionActivationMessage, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate NewVATSubmittedStoreOwnerNotification = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "NewVATSubmitted.StoreOwnerNotification");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(NewVATSubmittedStoreOwnerNotification, x => x.Subject, "%Store.Name%. New VAT number is submitted.", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(NewVATSubmittedStoreOwnerNotification, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />%Customer.FullName% (%Customer.Email%) has just submitted a new VAT number. Details are below:<br />VAT number: %Customer.VatNumber%<br />VAT number status: %Customer.VatNumberStatus%<br />Received name: %VatValidationResult.Name%<br />Received address: %VatValidationResult.Address%</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(NewVATSubmittedStoreOwnerNotification, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(NewVATSubmittedStoreOwnerNotification, x => x.Body, "Body", arLang.Id);
            }


            MessageTemplate OrderCancelledCustomerNotification = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "OrderCancelled.CustomerNotification");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(OrderCancelledCustomerNotification, x => x.Subject, "%Store.Name%. Your order cancelled", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(OrderCancelledCustomerNotification, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />Hello %Order.CustomerFullName%, <br />Your order has been cancelled. Below is the summary of the order. <br /><br />Order Number: %Order.OrderNumber%<br />Order Details: <a target=\"_blank\" href=\"%Order.OrderURLForCustomer%\">%Order.OrderURLForCustomer%</a><br />Date Ordered: %Order.CreatedOn%<br /><br /><br /><br />Billing Address<br />%Order.BillingFirstName% %Order.BillingLastName%<br />%Order.BillingAddress1%<br />%Order.BillingCity% %Order.BillingZipPostalCode%<br />%Order.BillingStateProvince% %Order.BillingCountry%<br /><br /><br /><br />Shipping Address<br />%Order.ShippingFirstName% %Order.ShippingLastName%<br />%Order.ShippingAddress1%<br />%Order.ShippingCity% %Order.ShippingZipPostalCode%<br />%Order.ShippingStateProvince% %Order.ShippingCountry%<br /><br />Shipping Method: %Order.ShippingMethod%<br /><br />%Order.Product(s)%</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(OrderCancelledCustomerNotification, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(OrderCancelledCustomerNotification, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate OrderCompletedCustomerNotification = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "OrderCompleted.CustomerNotification");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(OrderCompletedCustomerNotification, x => x.Subject, "%Store.Name%. Your order completed", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(OrderCompletedCustomerNotification, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />Hello %Order.CustomerFullName%, <br />Your order has been completed. Below is the summary of the order. <br /><br />Order Number: %Order.OrderNumber%<br />Order Details: <a target=\"_blank\" href=\"%Order.OrderURLForCustomer%\">%Order.OrderURLForCustomer%</a><br />Date Ordered: %Order.CreatedOn%<br /><br /><br /><br />Billing Address<br />%Order.BillingFirstName% %Order.BillingLastName%<br />%Order.BillingAddress1%<br />%Order.BillingCity% %Order.BillingZipPostalCode%<br />%Order.BillingStateProvince% %Order.BillingCountry%<br /><br /><br /><br />Shipping Address<br />%Order.ShippingFirstName% %Order.ShippingLastName%<br />%Order.ShippingAddress1%<br />%Order.ShippingCity% %Order.ShippingZipPostalCode%<br />%Order.ShippingStateProvince% %Order.ShippingCountry%<br /><br />Shipping Method: %Order.ShippingMethod%<br /><br />%Order.Product(s)%</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(OrderCompletedCustomerNotification, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(OrderCompletedCustomerNotification, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate ShipmentDeliveredCustomerNotification = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "ShipmentDelivered.CustomerNotification");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(ShipmentDeliveredCustomerNotification, x => x.Subject, "Your order from %Store.Name% has been delivered.", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ShipmentDeliveredCustomerNotification, x => x.Body, "<p><a href=\"%Store.URL%\"> %Store.Name%</a> <br /> <br /> Hello %Order.CustomerFullName%, <br /> Good news! You order has been delivered. <br /> Order Number: %Order.OrderNumber%<br /> Order Details: <a href=\"%Order.OrderURLForCustomer%\" target=\"_blank\">%Order.OrderURLForCustomer%</a><br /> Date Ordered: %Order.CreatedOn%<br /> <br /> <br /> <br /> Billing Address<br /> %Order.BillingFirstName% %Order.BillingLastName%<br /> %Order.BillingAddress1%<br /> %Order.BillingCity% %Order.BillingZipPostalCode%<br /> %Order.BillingStateProvince% %Order.BillingCountry%<br /> <br /> <br /> <br /> Shipping Address<br /> %Order.ShippingFirstName% %Order.ShippingLastName%<br /> %Order.ShippingAddress1%<br /> %Order.ShippingCity% %Order.ShippingZipPostalCode%<br /> %Order.ShippingStateProvince% %Order.ShippingCountry%<br /> <br /> Shipping Method: %Order.ShippingMethod% <br /> <br /> Delivered Products: <br /> <br /> %Shipment.Product(s)%</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(ShipmentDeliveredCustomerNotification, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(ShipmentDeliveredCustomerNotification, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate OrderPlacedCustomerNotification = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "OrderPlaced.CustomerNotification");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(OrderPlacedCustomerNotification, x => x.Subject, "Order receipt from %Store.Name%.", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(OrderPlacedCustomerNotification, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />Hello %Order.CustomerFullName%, <br />Thanks for buying from <a href=\"%Store.URL%\">%Store.Name%</a>. Below is the summary of the order. <br /><br />Order Number: %Order.OrderNumber%<br />Order Details: <a target=\"_blank\" href=\"%Order.OrderURLForCustomer%\">%Order.OrderURLForCustomer%</a><br />Date Ordered: %Order.CreatedOn%<br /><br /><br /><br />Billing Address<br />%Order.BillingFirstName% %Order.BillingLastName%<br />%Order.BillingAddress1%<br />%Order.BillingCity% %Order.BillingZipPostalCode%<br />%Order.BillingStateProvince% %Order.BillingCountry%<br /><br /><br /><br />Shipping Address<br />%Order.ShippingFirstName% %Order.ShippingLastName%<br />%Order.ShippingAddress1%<br />%Order.ShippingCity% %Order.ShippingZipPostalCode%<br />%Order.ShippingStateProvince% %Order.ShippingCountry%<br /><br />Shipping Method: %Order.ShippingMethod%<br /><br />%Order.Product(s)%</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(OrderPlacedCustomerNotification, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(OrderPlacedCustomerNotification, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate OrderPlacedStoreOwnerNotification = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "OrderPlaced.StoreOwnerNotification");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(OrderPlacedStoreOwnerNotification, x => x.Subject, "%Store.Name%. Purchase Receipt for Order #%Order.OrderNumber%", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(OrderPlacedStoreOwnerNotification, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />%Order.CustomerFullName% (%Order.CustomerEmail%) has just placed an order from your store. Below is the summary of the order. <br /><br />Order Number: %Order.OrderNumber%<br />Date Ordered: %Order.CreatedOn%<br /><br /><br /><br />Billing Address<br />%Order.BillingFirstName% %Order.BillingLastName%<br />%Order.BillingAddress1%<br />%Order.BillingCity% %Order.BillingZipPostalCode%<br />%Order.BillingStateProvince% %Order.BillingCountry%<br /><br /><br /><br />Shipping Address<br />%Order.ShippingFirstName% %Order.ShippingLastName%<br />%Order.ShippingAddress1%<br />%Order.ShippingCity% %Order.ShippingZipPostalCode%<br />%Order.ShippingStateProvince% %Order.ShippingCountry%<br /><br />Shipping Method: %Order.ShippingMethod%<br /><br />%Order.Product(s)%</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(OrderPlacedStoreOwnerNotification, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(OrderPlacedStoreOwnerNotification, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate ShipmentSentCustomerNotification = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "ShipmentSent.CustomerNotification");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(ShipmentSentCustomerNotification, x => x.Subject, "Your order from %Store.Name% has been shipped.", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ShipmentSentCustomerNotification, x => x.Body, "<p><a href=\"%Store.URL%\"> %Store.Name%</a> <br /><br />Hello %Order.CustomerFullName%!, <br />Good news! You order has been shipped. <br />Order Number: %Order.OrderNumber%<br />Order Details: <a href=\"%Order.OrderURLForCustomer%\" target=\"_blank\">%Order.OrderURLForCustomer%</a><br />Date Ordered: %Order.CreatedOn%<br /><br /><br /><br />Billing Address<br />%Order.BillingFirstName% %Order.BillingLastName%<br />%Order.BillingAddress1%<br />%Order.BillingCity% %Order.BillingZipPostalCode%<br />%Order.BillingStateProvince% %Order.BillingCountry%<br /><br /><br /><br />Shipping Address<br />%Order.ShippingFirstName% %Order.ShippingLastName%<br />%Order.ShippingAddress1%<br />%Order.ShippingCity% %Order.ShippingZipPostalCode%<br />%Order.ShippingStateProvince% %Order.ShippingCountry%<br /><br />Shipping Method: %Order.ShippingMethod% <br /> <br /> Shipped Products: <br /> <br /> %Shipment.Product(s)%</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(ShipmentSentCustomerNotification, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(ShipmentSentCustomerNotification, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate ProductProductReview = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "Product.ProductReview");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(ProductProductReview, x => x.Subject, "%Store.Name%. New product review.", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ProductProductReview, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />A new product review has been written for product \"%ProductReview.ProductName%\".</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(ProductProductReview, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(ProductProductReview, x => x.Body, "Body", arLang.Id);
            }


            MessageTemplate QuantityBelowStoreOwnerNotification = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "QuantityBelow.StoreOwnerNotification");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(QuantityBelowStoreOwnerNotification, x => x.Subject, "%Store.Name%. Quantity below notification. %Product.Name%", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(QuantityBelowStoreOwnerNotification, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />%Product.Name% (ID: %Product.ID%) low quantity. <br /><br />Quantity: %Product.StockQuantity%<br /></p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(QuantityBelowStoreOwnerNotification, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(QuantityBelowStoreOwnerNotification, x => x.Body, "Body", arLang.Id);
            }


            MessageTemplate ReturnRequestStatusChangedCustomerNotification = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "ReturnRequestStatusChanged.CustomerNotification");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(ReturnRequestStatusChangedCustomerNotification, x => x.Subject, "%Store.Name%. Return request status was changed.", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ReturnRequestStatusChangedCustomerNotification, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />Hello %Customer.FullName%,<br />Your return request #%ReturnRequest.ID% status has been changed.</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(ReturnRequestStatusChangedCustomerNotification, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(ReturnRequestStatusChangedCustomerNotification, x => x.Body, "Body", arLang.Id);
            }


            MessageTemplate ServiceEmailAFriend = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "Service.EmailAFriend");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(ServiceEmailAFriend, x => x.Subject, "%Store.Name%. Referred Item", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(ServiceEmailAFriend, x => x.Body, "<p><a href=\"%Store.URL%\"> %Store.Name%</a> <br /><br />%EmailAFriend.Email% was shopping on %Store.Name% and wanted to share the following item with you. <br /><br /><b><a target=\"_blank\" href=\"%Product.ProductURLForCustomer%\">%Product.Name%</a></b> <br />%Product.ShortDescription% <br /><br />For more info click <a target=\"_blank\" href=\"%Product.ProductURLForCustomer%\">here</a> <br /><br /><br />%EmailAFriend.PersonalMessage%<br /><br />%Store.Name%</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(ServiceEmailAFriend, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(ServiceEmailAFriend, x => x.Body, "Body", arLang.Id);
            }


            MessageTemplate WishlistEmailAFriend = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "Wishlist.EmailAFriend");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(WishlistEmailAFriend, x => x.Subject, "%Store.Name%. Wishlist", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(WishlistEmailAFriend, x => x.Body, "<p><a href=\"%Store.URL%\"> %Store.Name%</a> <br /><br />%Wishlist.Email% was shopping on %Store.Name% and wanted to share a wishlist with you. <br /><br /><br />For more info click <a target=\"_blank\" href=\"%Wishlist.URLForCustomer%\">here</a> <br /><br /><br />%Wishlist.PersonalMessage%<br /><br />%Store.Name%</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(WishlistEmailAFriend, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(WishlistEmailAFriend, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate CustomerNewOrderNote = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "Customer.NewOrderNote");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(CustomerNewOrderNote, x => x.Subject, "%Store.Name%. New order note has been added", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(CustomerNewOrderNote, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />Hello %Customer.FullName%, <br />New order note has been added to your account:<br />\"%Order.NewNoteText%\".<br /><a target=\"_blank\" href=\"%Order.OrderURLForCustomer%\">%Order.OrderURLForCustomer%</a></p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(CustomerNewOrderNote, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(CustomerNewOrderNote, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate RecurringPaymentCancelledStoreOwnerNotification = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "RecurringPaymentCancelled.StoreOwnerNotification");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(RecurringPaymentCancelledStoreOwnerNotification, x => x.Subject, "%Store.Name%. Recurring payment cancelled", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(RecurringPaymentCancelledStoreOwnerNotification, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />%Customer.FullName% (%Customer.Email%) has just cancelled a recurring payment ID=%RecurringPayment.ID%.</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(RecurringPaymentCancelledStoreOwnerNotification, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(RecurringPaymentCancelledStoreOwnerNotification, x => x.Body, "Body", arLang.Id);
            }

            MessageTemplate OrderPlacedVendorNotification = _messageTemplateRepository.Table.SingleOrDefault(x => x.Name == "OrderPlaced.VendorNotification");
            if (BlogBlogComment != null)
            {
                _localizedEntityService.SaveLocalizedValue(OrderPlacedVendorNotification, x => x.Subject, "%Store.Name%. Order placed", enLang.Id);
                _localizedEntityService.SaveLocalizedValue(OrderPlacedVendorNotification, x => x.Body, "<p><a href=\"%Store.URL%\">%Store.Name%</a> <br /><br />%Customer.FullName% (%Customer.Email%) has just placed on order. <br /><br />Order Number: %Order.OrderNumber%<br />Date Ordered: %Order.CreatedOn%</p>", enLang.Id);

                _localizedEntityService.SaveLocalizedValue(OrderPlacedVendorNotification, x => x.Subject, "Subject", arLang.Id);
                _localizedEntityService.SaveLocalizedValue(OrderPlacedVendorNotification, x => x.Body, "Body", arLang.Id);
            }
        }

        private void LocalizeProducts()
        {
            //English xml
            var enFilePath = _webHelper.MapPath("~/App_Data/Install/Products/en.xml");
            var enXmlDocument = new XmlDocument();
            enXmlDocument.Load(enFilePath);
            foreach (XmlNode node in enXmlDocument.SelectNodes("Products/Product"))
            {
                var proNameNode = node.SelectSingleNode("Name");
                if (proNameNode == null || string.IsNullOrEmpty(proNameNode.InnerText.Trim()))
                    continue;

                Product pro = _productRepository.Table.FirstOrDefault(p => p.Name.Equals(proNameNode.InnerText.Trim(), StringComparison.OrdinalIgnoreCase));
                if (pro == null) continue;

                var proLocNameNode = node.SelectSingleNode("LocalizedName");
                if (proLocNameNode != null && !string.IsNullOrEmpty(proLocNameNode.InnerText.Trim()))
                    _localizedEntityService.SaveLocalizedValue(pro, p => p.Name, proLocNameNode.InnerText, enLang.Id);

                var shortDescriptionNode = node.SelectSingleNode("ShortDescription");
                if (shortDescriptionNode != null && !string.IsNullOrEmpty(shortDescriptionNode.InnerText.Trim()))
                    _localizedEntityService.SaveLocalizedValue(pro, p => p.ShortDescription, shortDescriptionNode.InnerText, enLang.Id);

                var fullDescriptionNode = node.SelectSingleNode("FullDescription");
                if (fullDescriptionNode != null && !string.IsNullOrEmpty(fullDescriptionNode.InnerText.Trim()))
                    _localizedEntityService.SaveLocalizedValue(pro, p => p.FullDescription, fullDescriptionNode.InnerText, enLang.Id);
            }

            //arabic xml
            var arFilePath = _webHelper.MapPath("~/App_Data/Install/Products/ar.xml");
            var arXmlDocument = new XmlDocument();
            arXmlDocument.Load(arFilePath);

            foreach (XmlNode node in arXmlDocument.SelectNodes("Products/Product"))
            {
                var proNameNode = node.SelectSingleNode("Name");
                if (proNameNode == null || string.IsNullOrEmpty(proNameNode.InnerText.Trim()))
                    continue;

                Product pro = _productRepository.Table.FirstOrDefault(p => p.Name.Equals(proNameNode.InnerText.Trim(), StringComparison.OrdinalIgnoreCase));
                if (pro == null) continue;

                var proLocNameNode = node.SelectSingleNode("LocalizedName");
                if (proLocNameNode != null && !string.IsNullOrEmpty(proLocNameNode.InnerText.Trim()))
                    _localizedEntityService.SaveLocalizedValue(pro, p => p.Name, proLocNameNode.InnerText, arLang.Id);

                var shortDescriptionNode = node.SelectSingleNode("ShortDescription");
                if (shortDescriptionNode != null && !string.IsNullOrEmpty(shortDescriptionNode.InnerText.Trim()))
                    _localizedEntityService.SaveLocalizedValue(pro, p => p.ShortDescription, shortDescriptionNode.InnerText, arLang.Id);

                var fullDescriptionNode = node.SelectSingleNode("FullDescription");
                if (fullDescriptionNode != null && !string.IsNullOrEmpty(fullDescriptionNode.InnerText.Trim()))
                    _localizedEntityService.SaveLocalizedValue(pro, p => p.FullDescription, fullDescriptionNode.InnerText, arLang.Id);
            }

        }



        private void InstallCountriesAndStates_2(string defaultUserEmail)
        {
            var adminUser = _customerRepository.Table.FirstOrDefault(c => c.Email.Equals(defaultUserEmail));
            if (adminUser != null)
            {
                adminUser.ShippingAddress = null;
                adminUser.BillingAddress = null;
                adminUser.Addresses.Remove(adminUser.Addresses.First());
            }
            
            var addressRepository = EngineContext.Current.Resolve<IRepository<Address>>();
            var addresses = addressRepository.Table.ToList();
            foreach (var add in addresses)
            {
                addressRepository.Delete(add);
            }

            var states = _stateProvinceRepository.Table.ToList();
            foreach (var item in states)
            {
                _stateProvinceRepository.Delete(item);
            }
            var countriesToBeDeleted = _countryRepository.Table.ToList();
            foreach (var item in countriesToBeDeleted)
            {
                _countryRepository.Delete(item);
            }


            string filePath = _webHelper.MapPath("~/App_Data/Install/Countires/Countries_Cities.xml");
            var originalXmlDocument = new XmlDocument();
            originalXmlDocument.Load(filePath);

            List<Country> countries = new List<Country>();

            foreach (XmlNode node in originalXmlDocument.SelectNodes("Countries/Country"))
                countries.Add(new CountryParent(node).Country);

            countries.ForEach(c => _countryRepository.Insert(c));
        }

        private void LocalizeCountriesAndStates()
        {
            string filePath = _webHelper.MapPath("~/App_Data/Install/Countires/Countries_Cities.xml");
            var originalXmlDocument = new XmlDocument();
            originalXmlDocument.Load(filePath);
            
            var allCountries = _countryRepository.Table.ToList();

            foreach (XmlNode node in originalXmlDocument.SelectNodes("Countries/Country"))
            {
                string countryName = node.Attributes["Name"] != null ? node.Attributes["Name"].Value : null;
                if (string.IsNullOrEmpty(countryName)) continue;

                string locName = node.Attributes["ArabicName"] != null ? node.Attributes["ArabicName"].Value : null;
                if (string.IsNullOrEmpty(locName)) continue;

                var country = allCountries.FirstOrDefault(c => c.Name.Equals(countryName, StringComparison.InvariantCultureIgnoreCase));
                if (country == null) continue;

                _localizedEntityService.SaveLocalizedValue(country, x => x.Name, locName, arLang.Id);


                foreach (XmlNode cityNode in node.SelectNodes("Cities/City"))
                {
                    string cityName = cityNode.Attributes["Name"] != null ? cityNode.Attributes["Name"].Value : null;
                    if (string.IsNullOrEmpty(cityName)) continue;

                    string cityLocName = cityNode.Attributes["ArabicName"] != null ? cityNode.Attributes["ArabicName"].Value : null;
                    if (string.IsNullOrEmpty(cityLocName)) continue;

                    var state = country.StateProvinces.FirstOrDefault(c => c.Name.Equals(cityName, StringComparison.InvariantCultureIgnoreCase));
                    if (state == null) continue;

                    _localizedEntityService.SaveLocalizedValue(state, x => x.Name, locName, arLang.Id);
                }
            }

        }


        #region cities xml reader classes
        class CountryParent
        {
            public Country Country { get; set; }

            public CountryParent(XmlNode node)
            {
                if (node == null) throw new ArgumentNullException("node");

                Country = new Country();

                var nameNode = node.SelectSingleNode("Name");
                if (nameNode == null || String.IsNullOrEmpty(nameNode.InnerText.Trim())) throw new Exception("name node can not be null or empty");
                Country.Name = nameNode.InnerText.Trim();

                var twoLetterIsoCodeNode = node.SelectSingleNode("TwoLetterIsoCode");
                if (twoLetterIsoCodeNode == null || String.IsNullOrEmpty(twoLetterIsoCodeNode.InnerText.Trim())) throw new Exception("twoLetterIsoCode node can not be null or empty");
                Country.TwoLetterIsoCode = twoLetterIsoCodeNode.InnerText.Trim();

                var threeLetterIsoCodeNode = node.SelectSingleNode("ThreeLetterIsoCode");
                if (threeLetterIsoCodeNode == null || String.IsNullOrEmpty(threeLetterIsoCodeNode.InnerText.Trim())) throw new Exception("threeLetterIsoCode node can not be null or empty");
                Country.ThreeLetterIsoCode = threeLetterIsoCodeNode.InnerText.Trim();

                int nic = 0;
                var numericIsoCodeCodeNode = node.SelectSingleNode("NumericIsoCode");
                if (numericIsoCodeCodeNode == null || String.IsNullOrEmpty(numericIsoCodeCodeNode.InnerText.Trim()) || !int.TryParse(numericIsoCodeCodeNode.InnerText.Trim(), out nic))
                    throw new Exception("numericIsoCodeCode node can not be null or empty");
                Country.NumericIsoCode = nic;

                var publishedNode = node.SelectSingleNode("Published");
                if (publishedNode == null || String.IsNullOrEmpty(publishedNode.InnerText.Trim()))
                    throw new Exception("published node can not be null or empty");
                Country.Published = publishedNode.InnerText.Trim() == "1";

                int dis = 0;
                var displayOrderNode = node.SelectSingleNode("DisplayOrder");
                if (displayOrderNode != null && !String.IsNullOrEmpty(displayOrderNode.InnerText.Trim()) && int.TryParse(displayOrderNode.InnerText.Trim(), out dis))
                    Country.DisplayOrder = dis;
                
                foreach (XmlNode cityNode in node.SelectNodes("Cities/City"))
                {
                    this.Country.StateProvinces.Add(new StateParent(cityNode).StateProvince);
                }
            }
        }
        class StateParent
        {
            public StateProvince StateProvince { get; set; }

            public StateParent(XmlNode node)
            {
                if (node == null) throw new ArgumentNullException("node");
                StateProvince = new StateProvince();

                var nameNode = node.SelectSingleNode("Name");
                if (nameNode == null || String.IsNullOrEmpty(nameNode.InnerText.Trim()))
                    throw new Exception("name node can not be null or empty");
                StateProvince.Name = nameNode.InnerText.Trim();

                var abbreviationNode = node.SelectSingleNode("Abbreviation");
                //if (abbreviationNode == null || String.IsNullOrEmpty(abbreviationNode.InnerText.Trim()))
                //    throw new Exception("abbreviation node can not be null or empty");
                if (abbreviationNode != null && !String.IsNullOrEmpty(abbreviationNode.InnerText.Trim()))
                    StateProvince.Abbreviation = abbreviationNode.InnerText.Trim();

                //double lg = 0;
                //var longitudeNode = node.SelectSingleNode("Longitude");
                //if (longitudeNode != null && !String.IsNullOrEmpty(longitudeNode.InnerText.Trim()) && double.TryParse(longitudeNode.InnerText.Trim(), out lg))
                //    StateProvince.Longitude = lg;

                //double lat = 0;
                //var latitudeNode = node.SelectSingleNode("Latitude");
                //if (latitudeNode != null && !String.IsNullOrEmpty(latitudeNode.InnerText.Trim()) && double.TryParse(latitudeNode.InnerText.Trim(), out lat))
                //    StateProvince.Latitude = lat;

                //int utcOffset = 0;
                //var uTCOffsetNode = node.SelectSingleNode("UTCOffset");
                //if (uTCOffsetNode != null && !String.IsNullOrEmpty(uTCOffsetNode.InnerText.Trim()) && int.TryParse(uTCOffsetNode.InnerText.Trim(), out utcOffset))
                //    StateProvince.UTCOffset = utcOffset;
            }
        }
        #endregion
    }
}


